package imdbfolder.gui.util;

import java.awt.Dimension;
import java.awt.Font;

import javax.swing.JLabel;

public class TextWrapLabel extends JLabel {

    private static final long serialVersionUID = 1L;

    public TextWrapLabel(String string) {
        super(string);
    }

    public void setWrappedSize() {

        Font xx = getFont();
        int fontHeight = getFontMetrics(xx).getHeight();
        int stringWidth = getFontMetrics(xx).stringWidth(getText());
        int linesCount = (int) Math.floor(stringWidth / getWidth());
        linesCount = Math.max(1, linesCount + 2);
        setPreferredSize(new Dimension(100, (fontHeight + 2) * linesCount));

    }

}